﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Upreader.Application.Model;
using System.Linq.Expressions;

namespace Upreader.Application
{
    /// <summary>
    /// Defines the service for the application
    /// </summary>
    public interface IApplicationService
    {
        #region Download related methods

        IEnumerable<Download> GetDownloads(Expression<Func<Download, bool>> predicate);

        void AddDownload(Download download);

        void UpdateDownload(Download download);

        void RemoveDownload(Download download);

        /// <summary>
        /// Updates the priority of a download by placing it after the download with the ID specified
        /// If beforeDownloadId is null, the download will be prioritized at the end
        /// </summary>
        void UpdateDownloadPriority(Download download, Download beforeDownload);

        #endregion // Download related methods

        #region File related methods

        IEnumerable<File> GetFiles(Expression<Func<File, bool>> predicate);

        void UpdateFile(File file);

        void AddFile(File file);

        void RemoveFile(File file);

        /// <summary>
        /// Updates the priority of a file by placing it after the file with the ID specified
        /// If beforeFileId is null, the file will be prioritized at the end
        /// </summary>
        void UpdateFilePriority(File file, File beforeFile);

        #endregion // File related methods

        #region Segment related methods

        IEnumerable<Segment> GetSegments(Expression<Func<Segment, bool>> predicate);

        /// <summary>
        /// Get a set of segments which can be downloaded in priority order
        /// </summary>
        IEnumerable<Segment> GetSegmentsForDownload(int count, IEnumerable<int> excludeSet);

        void UpdateSegment(Segment segment);

        #endregion // Segment related methods

        #region Server related methods

        IEnumerable<Server> GetServers(Expression<Func<Server, bool>> predicate);

        void UpdateServer(Server server);

        void AddServer(Server server);

        void RemoveServer(Server server);

        /// <summary>
        /// Updates the priority of a server by placing it after the server with the ID specified
        /// If beforeServerId is null, the file will be prioritized at the end
        /// </summary>
        void UpdateServerPriority(Server server, Server beforeServer);

        #endregion // Server related methods

        #region Complex Methods

        void ParseNzbStream(System.IO.Stream stream, string fileName);

        #endregion // Complex Methods

        #region Events

        /// <summary>
        /// Event raised when one or more downloads are changed
        /// </summary>
        event ModelsChangedEventHandler DownloadsChanged;

        /// <summary>
        /// Event raised when one or more files are changed
        /// </summary>
        event ModelsChangedEventHandler FilesChanged;

        /// <summary>
        /// Event raised when one or more segments are changed
        /// </summary>
        event ModelsChangedEventHandler SegmentsChanged;

        /// <summary>
        /// Event raised when one or more severs are changed
        /// </summary>
        event ModelsChangedEventHandler ServersChanged;

        #endregion // Events
    }
}
